package com.itheima.Demo;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

public class Demo服务器端01 {
    public static void main(String[] args) throws IOException {
        //创建对象
        ServerSocketChannel ssc=ServerSocketChannel.open();
        //绑定端口
        ssc.bind(new InetSocketAddress(1314));
        //连接客户端
        SocketChannel sc = ssc.accept();
        //准备数组
        ByteBuffer buff = ByteBuffer.allocate(1024);
        //读取(返回值代表读取到的实际字节个数)
        int read = sc.read(buff);
        //打印
        System.out.println(new String(buff.array(),0,read));
        sc.close();
    }
}
